<template>
    <div>

        <div class="header" style="background-color: white">
            <el-page-header @back="goBack" content="管理公告">
            </el-page-header>
        </div>
        <el-divider></el-divider>
        <div v-show="ad==1">
            <el-form :inline="true" :model="admnotice" class="demo-form-inline">
                <el-form-item label="公告名称：">
                    <el-input v-model="admnotice.title" placeholder="公告名称"></el-input>
                </el-form-item>
                <el-form-item label="时间：">

                    <el-col :span="11">
                        <el-date-picker type="date" placeholder="选择日期" v-model="admnotice.noticeReleasetime" style="width: 100%;"></el-date-picker>
                    </el-col>
                    <el-col class="line" :span="2">-</el-col>
                    <el-col :span="11">
                        <el-date-picker type="date" placeholder="选择日期" v-model="admnotice.noticeNotificationtime" style="width: 100%;"></el-date-picker>
                    </el-col>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="GetAdmNotice">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="GetAdmNoticeadd">添加</el-button>
                </el-form-item>
            </el-form>
            <el-table border style="width: 100%" :data="admnotices.slice((currentPage-1)*pagesize,currentPage*pagesize)" >
                <el-table-column prop="title" label="公告名称："></el-table-column>
                <el-table-column prop="noticeNotificationtime" label="日期"></el-table-column>
                <el-table-column prop="uname" label="发布人"></el-table-column>
                <el-table-column prop="noticeFile" label="已阅" :show-overflow-tooltip='true'> </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-popover placement="right" width="150px" trigger="hover" :close-delay="100">
                            <el-button type="text" size="mini" @click="GetAdmNoticeById(scope)">查看</el-button>
                            <el-button type="text" size="mini" @click="GetAdmNoticeUpda(scope)">修改</el-button>
                            <el-button type="text" size="mini" @click="AdmNoticerom(scope)">删除</el-button>
                            <el-button slot="reference">操作</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="admnotices.length">
            </el-pagination>
        </div>
        <AdmNoticeAllX @back="ad=1" :notice="admnotic" v-if="ad==2"></AdmNoticeAllX>
        <AdmNoticeAdd :notice="admnotic" :ad="ad" @roves="rove" @update="update" v-if="ad==3"></AdmNoticeAdd>
    </div>
</template>

<script>
    import admnotice from "../../../model/gsl/AdmNotice/admnotice"
    import AdmNoticeAllX from "../AdmNotice/AdmNoticeAllX.vue"
    import AdmNoticeAdd from "../AdmNotice/AdmNoticeAdd.vue"
    const  adm =admnotice.getInstance();
    export default {
        components:{AdmNoticeAllX,AdmNoticeAdd},
        name: "AdmNoticetable",
        data() {
            return {   currentPage:1, //初始页
                pagesize:10,    //    每页的数
                admnotices:[],
                admnotice:{},
                admnotic:{},
                ad:1,
            };
        },
        created(){
            //后台请求数据
            this.GetAdmNotice();
        },
        methods: {

            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
            GetAdmNotice() {
                adm.list(this.admnotice).then((response) => {
                    this.admnotices = response.data.data;
                    this.admnotice ={}
                })
            },
            // GetAdmNotice() {
            //     adm.list(this.admnotice).then((response) => {
            //         this.admnotices = response.data.data;
            //         this.admnotice ={}
            //     })
            // },
            GetAdmNoticeById(adm){
                this.admnotic=adm.row;
                this.ad++;
            },
            AdmNoticerom(adm1){
                adm.romes(adm1.row.id).then(() => {
                    this.GetAdmNotice();
                })
            },
            GetAdmNoticeUpda(adm){
                this.admnotic={}
                this.admnotic=adm.row;
                this.ad=3;
            },
            update(notice){
                console.log(notice)
                if(!notice.id){
                    adm.add(notice).then(() => {
                        this.GetAdmNotice();
                        this.ad=1;
                    })
                }else {
                    adm.update(notice).then(() => {
                        this.GetAdmNotice();
                        this.ad=1;
                    })
                }
            },
            GetAdmNoticeadd(){
                this.admnotic={}
                this.ad=3;
            },
            rove(a){
                this.ad=a;
            },
            goBack(){
                history.back()
            }
        }
    }
</script>

<style scoped>

</style>
